package com.primaryedu.ui.inform;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.primaryedu.R;
import com.primaryedu.data.Contants;
import com.primaryedu.data.GlobalData;
import com.primaryedu.ui.BaseActivity;

public class InformDetailActivity extends BaseActivity implements OnClickListener {
    private String contentStr, dateStr, noticeid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_inform_detail);

        contentStr = getIntent().getStringExtra("contentStr");
        dateStr = getIntent().getStringExtra("dateStr");
        noticeid = getIntent().getStringExtra("noticeid");
        init();
    }

    private void init() {
        ((TextView) findViewById(R.id.title)).setText("通知详情");
        findViewById(R.id.back).setOnClickListener(this);
        ((TextView) findViewById(R.id.text_date)).setText(dateStr);
        ((TextView) findViewById(R.id.text_content)).setText(contentStr);

        requestData();
    }

    @Override
    protected int BindLayout() {
        return R.layout.activity_inform_detail;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;

            default:
                break;
        }
    }

    private void requestData() {
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Contants.saveRecord,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        System.out.println("saveRecord==" + response);

                        try {
                            JSONObject json = new JSONObject(response);
                            int result = json.getInt("result");

                            if (result == 1) {

                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("noticeid", noticeid);
                map.put("userid", GlobalData.getUserId(getApplicationContext()));
                return map;
            }
        };
        requestQueue.add(stringRequest);

    }

}
